package com.treasure.hunt.task

import android.animation.ObjectAnimator
import android.animation.ValueAnimator.RESTART
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.view.animation.LinearInterpolator
import com.blankj.utilcode.util.LogUtils
import com.module.lemlin.base.BaseAbstractActivity
import com.treasure.hunt.R
import kotlinx.android.synthetic.main.activity_task_lucky.*


class TaskLuckyActivity : BaseAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, TaskLuckyActivity::class.java)
            activity.startActivity(intent)
        }
    }

    private val angle: MutableList<Float> =
        mutableListOf(45f, 90f, 135f, 180f, 225f, 270f, 315f, 360f)

    override val layoutResId: Int
        get() = R.layout.activity_task_lucky

    override fun stateBar(): StatusBar {
        return StatusBar(
            isLightMode = false,
            bottomColor = R.color.FF_FFA759,
            view = flTaskLuckyBar
        )
    }

    @SuppressLint("ResourceType")
    override fun initView() {
        angle.forEach {
            flTaskLuckyBody.addView(createLuckyGoodsView(it))
        }

        tvTaskLuckyStart.setOnClickListener {
            val animation: Animation =
                AnimationUtils.loadAnimation(this as Context, R.animator.rotate_shun)
            animation.interpolator = LinearInterpolator()
            flTaskLuckyPointer.startAnimation(animation)
        }

        flTaskLuckyPointer.setOnClickListener {
            flTaskLuckyPointer.clearAnimation()
        }
    }

    private fun createLuckyGoodsView(rotation: Float): View {
        return layoutInflater.inflate(R.layout.item_goods_lucky, null).apply {
            this.rotation = rotation
        }
    }
}